<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<%

	String aaName="";
	aaName=(String)request.getAttribute("aaName");
	String bbName="";
	bbName=(String)request.getAttribute("bbName");
	String staId="";
	staId=(String)request.getAttribute("staId");
%>
<html>
<head>
	<title>设备临时位置管理</title>
	<meta name="decorator" content="ani"/>
	<script>

        var aName='<%=aaName%>';
        var bName='<%=bbName%>';
	</script>
	<script type="text/javascript">

		var validateForm;
		var $table; // 父页面table表格id
		var $topIndex;//弹出窗口的 index
		function doSubmit(table, index){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		   //判断数据
            var aDevTName=$("#aDevTName").val();
            var baseDevTName=$("#baseDevTName").val();
            var bDevTName=$("#bDevTName").val();

            if((aDevTName!=""&&baseDevTName!=""&&aDevTName==baseDevTName)||(aDevTName!=""&&bDevTName!=""&&aDevTName==bDevTName)||(baseDevTName!=""&&bDevTName!=""&&baseDevTName==bDevTName)){
                jp.error("选择设备不能重复");
                return false;
			}
			//重新赋值
            $("#aDev").val($("#aDevTId").val());
            $("#baseDev").val($("#baseDevTId").val());
            $("#bDev").val($("#bDevTId").val());

			if(validateForm.form()){
			  $table = table;
			  $topIndex = index;
			  jp.loading();
			  $("#inputForm").submit();
			  return true;
		  }

		  return false;
		}

		$(document).ready(function() {

            jp.get("${ctx}/devlocal/devLocalTmp/allDevice" , function(data){
                var allDevice=data;
                $("#aDevId").val($("#aDev").val());
                $("#baseDevId").val($("#baseDev").val());
                $("#bDevId").val($("#bDev").val());
                $("#aDevTId").val($("#aDev").val());
                $("#baseTDevId").val($("#baseDev").val());
                $("#bDevTId").val($("#bDev").val());
                var aDevName="";
                var baseDevName="";
                var bDevName="";
                for(var i=0;i<allDevice.length;i++){
                    if(allDevice[i].id==$("#aDev").val()){
                        aDevName=allDevice[i].code;
                    }
                    if(allDevice[i].id==$("#baseDev").val()){
                        baseDevName=allDevice[i].code;
                    }
                    if(allDevice[i].id==$("#bDev").val()){
                        bDevName=allDevice[i].code;
                    }
                }

                $("#aDevTName").val(aDevName);
                $("#baseDevTName").val(baseDevName);
                $("#bDevTName").val(bDevName);
            })




			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					jp.post("${ctx}/devlocal/devLocalTmp/save",$('#inputForm').serialize(),function(data){
						if(data.success){
	                    	$table.bootstrapTable('refresh');
	                    	jp.success(data.msg);
	                    	jp.close($topIndex);//关闭dialog

	                    }else{
            	  			jp.error(data.msg);
	                    }
					})
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
		});
	</script>
</head>
<body class="bg-white">
		<form:form id="inputForm" modelAttribute="devLocalTmp" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>	
		<table class="table table-bordered">
		   <tbody>
		  		 <form:hidden path="aDev" id="aDev"/>
				 <form:hidden path="baseDev" id="baseDev"/>
				 <form:hidden path="bDev" id="bDev"/>
				<tr>
					<td class="width-8 active"><label class="pull-right"><%=aaName%>设备：</label></td>
					<td class="width-23">

						<sys:gridselect url="${ctx}/device/device/dataBySta?devStation.id=${staId}" isMultiSelected="false"  id="aDevT" name="aDevT" value="" labelName="dev.code" labelValue=""
										title="选择设备" cssClass="form-control " fieldLabels="设备" fieldKeys="code" searchLabels="设备" searchKeys="code" ></sys:gridselect>

					</td>
					<td class="width-8 active"><label class="pull-right">基坑设备：</label></td>
					<td class="width-23">
						<sys:gridselect url="${ctx}/device/device/dataBySta?devStation.id=${staId}" isMultiSelected="false"  id="baseDevT" name="baseDevT" value="" labelName="dev.code" labelValue=""
										title="选择设备" cssClass="form-control " fieldLabels="设备" fieldKeys="code" searchLabels="设备" searchKeys="code" ></sys:gridselect>

					</td>
					<td class="width-8 active"><label class="pull-right"><%=bbName%>设备：</label></td>
					<td class="width-23">

						<sys:gridselect url="${ctx}/device/device/dataBySta?devStation.id=${staId}" isMultiSelected="false"  id="bDevT" name="bDevT" value="" labelName="dev.code" labelValue=""
										title="选择设备" cssClass="form-control " fieldLabels="设备" fieldKeys="code" searchLabels="设备" searchKeys="code" ></sys:gridselect>

					</td>
				</tr>

		 	</tbody>
		</table>
	</form:form>
</body>
</html>
<script>

</script>